<?php

/**
 * debates actions.
 *
 * @package    LYPO
 * @subpackage debates
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 9301 2008-05-27 01:08:46Z dwhittle $
 */
class debatesActions extends sfActions
{
	public function preExecute(){
		if(sfConfig::get('sf_web_debug')==true){
			$this->setLayout('layout');
		}else{
			$this->setLayout(false);
		}
		$this->setTemplate('default');
	}
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeDebates(sfWebRequest $request)
	{
		$result = new LypoResult();
		$userid = $request->getParameter('userid');
		$view = $request->getParameter('view','byname');
		//Pagina's regelen
		$byday_page = $this->getRequestParameter('byday_page',1);
		$byname_page = $this->getRequestParameter('byname_page',1);
		$respected_page = $this->getRequestParameter('respected_page',1);
		
		if(!$view){
			$result->setErrorMessage("No view given: byname | byday | respected");
			return $this->renderText(print_r($result->toArray(),1));
		}
		try {
			/* @var $user User */
			$user = UserPeer::getByContainerString($userid);
			if($user){
				$this->partial = 'debates';

				//LET OP Dit
				$all_debates = LypoStatementPeer::getDebatesByNamePager($byname_page);

				//Repected debates ophalen met pager
				$respected_debates = LypoStatementPeer::getRespectedDebatesPager($respected_page);
							
				//Debatten op dag
				$daily_debates = LypoStatementPeer::getRecentDebatesPager($byday_page);
				$this->args = array('user' => $user, 'view' => $view,  'all_debates' => $all_debates, 'daily_debates' => $daily_debates, 'respected_debates' => $respected_debates, 'userid' => $userid);
				
				
				//return $this->renderPartial('debates');
			}else{
				$result->setErrorMessage("User not found");
				return $this->renderText(print_r($result->toArray(),1));
			}
		}catch( Exception $e){
			$result->setErrorMessage($e->getMessage());
			return $this->renderText(print_r($result->toArray(),1));
		}
	}
}
